
package com.lanwf.admin.sys.index;

import com.jfinal.aop.Clear;
import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.kit.Ret;
import com.lanwf.admin.BaseController;
import com.lanwf.common.model.SysAdmin;
import com.lanwf.admin.utils.Cons;
import com.lanwf.admin.vo.Menus;

import java.util.List;

/**
 * 后台首页控制层
 */
@Path(value = "/admin", viewPath = "/admin/index")
public class IndexAdminController extends BaseController {

	@Inject
	IndexAdminService srv;

	public IndexAdminController() {
	}

/*	@ActionKey("/")
	public void frontIndex() {
		this.redirect("/admin");
	}*/

	public void main() {
		this.render("main.html");
	}

	public void skin() {
	}

	public void lockscreen() {
		this.setCookie("lockscreen", "1", Cons.ADMIN_COOKIE_expires, true);
	}

	@Clear
	public void unlockscreen() {
		String id = this.get("id");
		String password = this.get("password", "").trim();
		SysAdmin first = (SysAdmin)SysAdmin.dao.findFirst("select *  from sys_admin where id = ? and password = ? ", new Object[]{id, password});
		if (first == null) {
			this.renderJson(Ret.fail().set("msg", "密码不正确,请重新输入。"));
		} else {
			this.removeCookie("lockscreen");
			this.renderJson(Ret.ok());
		}
	}

	public void index() {
		List<Menus> menus = this.srv.getListMenus(getAccount());
		this.set("menus", menus);
		this.render("index.html");
	}

	public void switchSkin() {
		this.render("skin.html");
	}

	public void resetPwd() {
		this.render("resetPwd.html");
	}

	public void updatePassword() {
		SysAdmin admin = new SysAdmin();
		admin.setId(this.getInt("id"));
		admin.setPassword(this.get("password"));
		admin.update();
		this.renderJson(Ret.ok().set("msg", "更新成功").set("code", 0));
	}
	
}


